﻿using Microsoft.Expression.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuperFrame.Charts
{
    /// <summary>
    /// Percentage.xaml 的交互逻辑
    /// </summary>
    public partial class Percentage : UserControl
    {
        public Percentage()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 背景色
        /// </summary>
        public Brush BackColor { get { return (Brush)GetValue(BackColorProperty); } set { SetValue(BackColorProperty, value); } }
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register("BackColor", typeof(Brush), typeof(Percentage), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1E1E1E"))));
        /// <summary>
        /// 背景透明度
        /// </summary>
        public double BackOpacity { get { return (double)GetValue(BackOpacityProperty); } set { SetValue(BackOpacityProperty, value); } }
        public static readonly DependencyProperty BackOpacityProperty = DependencyProperty.Register("BackOpacity", typeof(double), typeof(Percentage), new PropertyMetadata(0.4));

        /// <summary>
        /// 进度条色 
        /// </summary>
        public Brush ProgressColor { get { return (Brush)GetValue(ProgressColorProperty); } set { SetValue(ProgressColorProperty, value); } }
        public static readonly DependencyProperty ProgressColorProperty = DependencyProperty.Register("ProgressColor", typeof(Brush), typeof(Percentage), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3de2ff"))));
        /// <summary>
        /// 进度条宽度
        /// </summary>
        public double ProgressThickness { get { return (double)GetValue(ProgressThicknessProperty); } set { SetValue(ProgressThicknessProperty, value); } }
        public static readonly DependencyProperty ProgressThicknessProperty = DependencyProperty.Register("ProgressThickness", typeof(double), typeof(Percentage), new PropertyMetadata(20.0));

        /// <summary>
        /// 字体大小
        /// </summary>
        public int TextSize { get { return (int)GetValue(TextSizeProperty); } set { SetValue(TextSizeProperty, value); } }
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register("TextSize", typeof(int), typeof(Percentage), new PropertyMetadata(22));
        /// <summary>
        /// 后缀字体大小
        /// </summary>
        public int SuffixSize { get { return (int)GetValue(SuffixSizeProperty); } set { SetValue(SuffixSizeProperty, value); } }
        public static readonly DependencyProperty SuffixSizeProperty = DependencyProperty.Register("SuffixSize", typeof(int), typeof(Percentage), new PropertyMetadata(16));


        /// <summary>
        /// 后缀内容
        /// </summary>
        public string SuffixTxt { get { return (string)GetValue(SuffixTxtProperty); } set { SetValue(SuffixTxtProperty, value); } }
        public static readonly DependencyProperty SuffixTxtProperty = DependencyProperty.Register("SuffixTxt", typeof(string), typeof(Percentage), new PropertyMetadata("%"));
        /// <summary>
        /// 标题内容
        /// </summary>
        public string TitleText { get { return (string)GetValue(TitleTextProperty); } set { SetValue(TitleTextProperty, value); } }
        public static readonly DependencyProperty TitleTextProperty = DependencyProperty.Register("TitleText", typeof(string), typeof(Percentage), new PropertyMetadata("标题"));

        /// <summary>
        /// 标题后缀
        /// </summary>
        public string TitleTxtSuffix { get { return (string)GetValue(TitleTxtSuffixProperty); } set { SetValue(TitleTxtSuffixProperty, value); } }
        public static readonly DependencyProperty TitleTxtSuffixProperty = DependencyProperty.Register("TitleTxtSuffix", typeof(string), typeof(Percentage), new PropertyMetadata("%"));

        /// <summary>
        /// 标题颜色
        /// </summary>
        public Brush TitleColor { get { return (Brush)GetValue(TitleColorProperty); } set { SetValue(TitleColorProperty, value); } }
        public static readonly DependencyProperty TitleColorProperty = DependencyProperty.Register("TitleColor", typeof(Brush), typeof(Percentage), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3de2ff"))));

        /// <summary>
        /// 标题字体大小 （可为空，默认系统字体大小）
        /// </summary>
        public int TitleSize { get { return (int)GetValue(TitleSizeProperty); } set { SetValue(TitleSizeProperty, value); } }
        public static readonly DependencyProperty TitleSizeProperty = DependencyProperty.Register("TitleSize", typeof(int), typeof(Percentage), new PropertyMetadata(16));

        /// <summary>
        /// 最大值
        /// </summary>
        public double ProgressMax { get { return (double)GetValue(ProgressMaxProperty); } set { SetValue(ProgressMaxProperty, value); } }
        public static readonly DependencyProperty ProgressMaxProperty = DependencyProperty.Register("ProgressMax", typeof(double), typeof(Percentage), new PropertyMetadata(100.0));

        /// <summary>
        /// 当前百分比
        /// </summary>
        public int PercentageValue
        {
            get { return (int)GetValue(PercentageValueProperty); }
            set { SetValue(PercentageValueProperty, value); }
        }
        public static readonly DependencyProperty PercentageValueProperty = DependencyProperty.Register("PercentageValue", typeof(int), typeof(Percentage), new PropertyMetadata(0));

        /// <summary>
        /// 进度条值
        /// </summary>
        public double ProgressValue { get { return (double)GetValue(ProgressValueProperty); } set { SetValue(ProgressValueProperty, value); } }
        public static readonly DependencyProperty ProgressValueProperty = DependencyProperty.Register("ProgressValue", typeof(double), typeof(Percentage), new PropertyMetadata(0.0, ValueChange));
        public static void ValueChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as Percentage).StoryboardPlay(e);
        }
        protected void StoryboardPlay(DependencyPropertyChangedEventArgs e)
        {
            PercentageValue = Convert.ToInt32(Convert.ToDouble(e.NewValue) / ProgressMax * 100);
            DoubleAnimation da = new DoubleAnimation();
            da.To = double.Parse(e.NewValue.ToString()) * (360 / ProgressMax);
            da.Duration = new Duration(TimeSpan.Parse("0:0:0.4"));
            PanelArc.BeginAnimation(Arc.EndAngleProperty, da);
        }

    }
}
